package core.DAO.implementation;

import hibernate.util.HibernateUtil;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import core.DAO.interfaces.AvizDao;
import core.entities.Aviz;

public class AvizDaoImpl implements AvizDao {

	@Override
	public List<Aviz> getAllAviz() {
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = null;
		List<Aviz> aviz = null;
		try {
			transaction = session.beginTransaction();
			Query query = session.createQuery("from Aviz");
			aviz = query.list();
			transaction.commit();
		} catch (HibernateException e) {
			transaction.rollback();
			e.printStackTrace();
		} finally {
			session.close();
		}
		return aviz;
	}

	@Override
	public Aviz getAvizById(int id) {
		// TODO Auto-generated method stub
		return null;
	}

}
